﻿#ifndef PHYSICS_WORLD_FUNCTIONS
#define PHYSICS_WORLD_FUNCTIONS 1

#include <vector>

#include <iostream>

#include <osg/Vec3>
#include <osg/Node>
#include <BulletLibDefine.h>
#include <btBulletDynamicsCommon.h>
#include <Define.h>
#include <ContactTestCallBack.h>
//#include <ContactTestCallBack.h>

namespace PhysicsWorldFunctions
{
enum COLLISION_SHAPE
{
    // polyhedral convex shapes
    BOX_SHAPE_PROXYTYPE,
    TRIANGLE_SHAPE_PROXYTYPE,
    TETRAHEDRAL_SHAPE_PROXYTYPE,
    CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE,
    CONVEX_HULL_SHAPE_PROXYTYPE,
    CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE,
    CUSTOM_POLYHEDRAL_SHAPE_TYPE,
    //implicit convex shapes
    IMPLICIT_CONVEX_SHAPES_START_HERE,
    SPHERE_SHAPE_PROXYTYPE,
    MULTI_SPHERE_SHAPE_PROXYTYPE,
    CAPSULE_SHAPE_PROXYTYPE,
    CONE_SHAPE_PROXYTYPE,
    CONVEX_SHAPE_PROXYTYPE,
    CYLINDER_SHAPE_PROXYTYPE,
    UNIFORM_SCALING_SHAPE_PROXYTYPE,
    MINKOWSKI_SUM_SHAPE_PROXYTYPE,
    MINKOWSKI_DIFFERENCE_SHAPE_PROXYTYPE,
    BOX_2D_SHAPE_PROXYTYPE,
    CONVEX_2D_SHAPE_PROXYTYPE,
    CUSTOM_CONVEX_SHAPE_TYPE,
    //concave shapes
    CONCAVE_SHAPES_START_HERE,
    //keep all the convex shapetype below here, for the check IsConvexShape in broadphase proxy!
    TRIANGLE_MESH_SHAPE_PROXYTYPE
};

//数据类型转换
BULLET_EDITOR_DLL osg::Vec3 btVector3ToOsgVec3(const btVector3& bt_vec3 );

//刚体模型生成
BULLET_EDITOR_DLL btRigidBody* creatRigidBodyFromOsgNode(osg::ref_ptr<osg::Node> osg_node, double mass, COLLISION_SHAPE collision_shape_enum);
BULLET_EDITOR_DLL void creatRigidGround();
BULLET_EDITOR_DLL void creatRigidBodyForChildNode(osg::ref_ptr<osg::Node> osg_node);
BULLET_EDITOR_DLL osg::Node* rigidBodyToOsgNode(btRigidBody* rigidPtr);
BULLET_EDITOR_DLL btRigidBody* findRigidBodyByNodeName(std::string nodeName);
BULLET_EDITOR_DLL std::vector<osg::Vec3> rigidBodyObbAxis(btRigidBody* rigidPtr);

//Debug_Draw调试绘制
BULLET_EDITOR_DLL void enablePhysicsDebugDraw();
BULLET_EDITOR_DLL void disablePhysicsDebugDraw();
BULLET_EDITOR_DLL bool getEnableDebugDraw();


//重力相关
BULLET_EDITOR_DLL void setGravity(double x, double y, double z);
BULLET_EDITOR_DLL osg::Vec3 getGravity();

//打开或关闭动力学计算
BULLET_EDITOR_DLL void enableDynamic();
BULLET_EDITOR_DLL void disableDynamic();

//碰撞测试函数，通过物体的名称进行识别
//BULLET_EDITOR_DLL bool contactTestByNameAndMatrix(const std::string& model_name, const osg::Matrix& m);

//获取刚体的个数
BULLET_EDITOR_DLL int getRigidBodyMapSize();

//获取刚体的名称
BULLET_EDITOR_DLL std::string getRigidBodyName(int map_index);

//physicsWorld相关
BULLET_EDITOR_DLL btRigidBody* physicsWorldGetRigidBody( int int_id);
BULLET_EDITOR_DLL bool rigidBodyIsAvailable(int int_id);

//rigidBody相关
BULLET_EDITOR_DLL void rigidBodyApplyCentralForce( btRigidBody* body_ptr, double x, double y, double z);
BULLET_EDITOR_DLL osg::Vec3 rigidBodyGetLinearVelocity( btRigidBody* body_ptr);

//调用contactTestCallBack
BULLET_EDITOR_DLL void contactTestByIdStr(int int_id);
//contactTestCallBack相关
BULLET_EDITOR_DLL int contactTestCallBackGetManifoldVectorSize(int int_id);

//SeparateDirection分离方向
BULLET_EDITOR_DLL osg::Vec3 computeSeparateDirection(int int_id);


//实时碰撞检测开关
BULLET_EDITOR_DLL void enableRealTimeCollisioinDetection();
BULLET_EDITOR_DLL void disableRealTimeCollisioinDetection();
BULLET_EDITOR_DLL bool getEnableRealTimeCollisioinDetection();

//openTissue's function
void writeTransformToObjFileForOpenTissue(btCollisionObject *objWrapper);

//write information about rigid body to xml file.
BULLET_EDITOR_DLL void writeRigidBodyInfoToXML();

//write a zip file to import all rigid body files
BULLET_EDITOR_DLL void writeZipOfRigidBody();
//send zip to socket
void sendZipTOSocket();
}
#endif //!PHYSICS_WORLD_FUNCTIONS
